import axios from 'axios';
console.log('获取');
const sitemap = {
	path:'/sitemap.xml',
	hostname:'http://www.huxlog.com/',
	cacheTime:1000 * 60 * 60 * 24,
	gzip:true,
	generate:false,
	exclude:['/error','/examplepage','/usermessage'],
	defaults:{
		changefreq:'always',
		lastmod:new Date()
	},
	routes:async ()=>{
		let routes = [];
		let result = await axios.get('http://localhost:3000/api/getallarticle');
		 routes = result.data.data.map(item=>{
			return {
				url:`/webpage/articles/${item}`,
				changefreq:'always',
				lastmod:new Date()
			}
		});
		result = await axios.get('http://localhost:3000/api/getalltypepage');
		result.data.data.forEach(item=>{
			if(item.num > 0){
				let len = Math.ceil(item.num/10);
				for(let i = 1;i <= len;i++ ){
					routes.push({
						url:`/webpage/types/${item.id}/${len}`,
						changefreq:'always',
						lastmod:new Date()
					})
				}
			}
		});
		result = await axios.get('http://localhost:3000/api/getalltagpage');
		result.data.data.forEach(item=>{
			if(item.num > 0){
				let len = Math.ceil(item.num/10);
				for(let i = 1;i <= len;i++ ){
					routes.push({
						url:`/webpage/tags/${item.id}/${len}`,
						changefreq:'always',
						lastmod:new Date()
					})
				}
			}
		});
		return routes;
	}
};
export default sitemap;